<?php
include_once("./Db_pdo.class.php");


ini_set('date.timezone','Asia/Shanghai');
// $DB=new Db_pdo("jmshop","root","root");
// $DB=new Db_pdo("cxh_v3_test","cxhv3","cxhv3pwd!@#");
$DB=new Db_pdo("cxh_v3","cxhv3","cxhv3pwd!@#");
echo '<pre>';

set_time_limit(0);

//门票补贴
// $field = 'su.id,su.aplt_totel_retime,su.aplt_totel_money,su.aplt_totel_days,su.aplt_totel_balance,su.aplt_re_money,su.aplt_re_money_p,su.aplt_re_integral,su.aplt_re_integral_p,su.aplt_re_fee,su.aplt_re_fee_p,su.member_id,me.credit2,me.credit1,me.cxhname';
// $sql = 'select '.$field.' from ims_cxh_apply_subsidy_things as su inner join ims_ewei_shop_member as me on su.member_id=me
// 	.id where su.aplc_status=1 and su.is_all_back=1 and su.is_month_back=1';

// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC);  
// foreach ($data as $key => $value) {
// 	if($value['aplt_totel_money']>$value['aplt_re_money']){
// 				//每天返款总金额
// 				$money = round($value['aplt_totel_balance']/($value['aplt_totel_days']-$value['aplt_totel_retime']),2);
// 				//剩余金额(防止返款不足的情况)
// 				// echo $money;
// 				$sql1 = "update ims_ewei_shop_member set credit2=credit2+".$money.' where id='.$value['member_id'];
// 				// echo $sql1;
// 				// echo '<br>';
// 				$DB->new_query($sql1);
// 				//添加member表的钱

// 	}
// }

//车辆
// $field = 'su.id,su.aplc_totel_retime,su.aplc_totel_money,su.aplc_totel_days,su.aplc_totel_balance,su.aplc_re_money,su.aplc_re_money_p,su.aplc_re_integral,su.aplc_re_integral_p,su.aplc_re_fee,su.aplc_re_fee_p,su.member_id,me.credit2,me.credit1,me.cxhname';
// $sql = 'select '.$field.' from ims_cxh_apply_subsidy_car as su inner join ims_ewei_shop_member as me on su.member_id=me
// 	.id where su.aplc_status=1 and su.is_all_back=1 and su.is_month_back=1';
// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC);  

// // print_r($data);
// foreach ($data as $key => $value) {
// 	//判断已经返还完的
// 			if($value['aplc_totel_money']>$value['aplc_re_money']){
// 				//每天返款总金额
// 				$money = round($value['aplc_totel_balance']/($value['aplc_totel_days']-$value['aplc_totel_retime']),2);
// 				// echo $money;
// 				//剩余金额(防止返款不足的情况)
// 				if($value['aplc_totel_balance']<$money){
// 					$param['aplc_totel_balance'] = 0;
// 					$money = $value['aplc_totel_balance'];
// 				}else{
// 					$param['aplc_totel_balance'] = $value['aplc_totel_balance']-$money;
// 				}
// 				// echo $money;
// 				//金额(判断是否全返款还是其他)
// 				$fee_money =0;
// 				if($value['aplc_re_fee_p']>0){
// 					$fee_money = round($money*$value['aplc_re_fee_p'],2);
// 					$balance_money =  round($money-$fee_money,2);
// 				}else{
// 					$balance_money = $money;
// 				}


// 				// echo $balance_money;
// 				$sql1 = "update ims_ewei_shop_member set credit2=credit2+".$balance_money.' where id='.$value['member_id'];
// 				// echo $sql1;
// 				// echo '<br>';
// 				$DB->new_query($sql1);

// 			}

// }

//代理商

// $field = 'su.id,su.apla_totel_retime,su.apla_totel_money,su.apla_totel_days,su.apla_totel_balance,su.apla_re_money,su.apla_re_money_p,su.apla_re_integral,su.apla_re_integral_p,su.apla_re_fee,su.apla_re_fee_p,su.member_id,me.credit2,me.credit1,me.cxhname';
// $sql = 'select '.$field.' from ims_cxh_apply_subsidy_agent as su inner join ims_ewei_shop_member as me on su.member_id=me
// 	.id where su.apla_status=1 and su.is_all_back=1 and su.is_month_back=1';

// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// // print_r($data); 
// foreach ($data as $key => $value) {
// 	if($value['apla_totel_money']>$value['apla_re_money']){

// 				//每天返款总金额
// 				$money = round($value['apla_totel_balance']/($value['apla_totel_days']-$value['apla_totel_retime']),2);

// 				//剩余金额(防止返款不足的情况)
// 				if($value['apla_totel_balance']<$money){
// 					$param['apla_totel_balance'] = 0;
// 					$money = $value['apla_totel_balance'];
// 				}else{
// 					$param['apla_totel_balance'] = $value['apla_totel_balance']-$money;
// 				}
// 				$fee_money =0;
// 				if($value['apla_re_fee_p']>0){
// 					$fee_money = round($money*$value['apla_re_fee_p'],2);
// 					$balance_money =  round($money-$fee_money,2);
// 				}else{
// 					$balance_money = $money;
// 				}

// 				// echo $balance_money;
// 				$sql1 = "update ims_ewei_shop_member set credit2=credit2+".$balance_money.' where id='.$value['member_id'];
				
// 				$DB->new_query($sql1);

	
// 			}
// }


// $sql = 'select * from ims_cxh_cash_log where cash_bus_type=50 and ctime>1533969138 and id <=510794';

// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// foreach ($data as $key => $value) {
// 	// $value['cash_now'];
// 	$sql1 = "update ims_ewei_shop_member set credit2=credit2-".$value['cash_now'].' where id='.$value['member_id'];
				
// 	$DB->new_query($sql1);
// }

// print_r($data);








